// 简单UDP客户端
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>

#pragma comment(lib, "ws2_32.lib")

int main()
{
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2, 2), &wsaData);

    char *server = "127.0.0.1";
    char *sendbuf = "hello world";

    struct sockaddr_in servAddr;
    servAddr.sin_family = AF_INET;
    servAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    servAddr.sin_port = htons(8080);

    int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    int len = sizeof(servAddr);
    sendto(s, sendbuf, strlen(sendbuf), 0, (struct sockaddr *)&servAddr, sizeof(servAddr));
    recvfrom(s, sendbuf, sizeof(sendbuf), 0, (struct sockaddr *)&servAddr, &len);
    printf("%s\n", sendbuf);

    closesocket(s);
    WSACleanup();
    return 0;
}
